本文主要介绍了sysbench的安装和使用。
1. sysbench简介
sysbench is a scriptable multi-threaded benchmark tool based on LuaJIT. It is most frequently used for database benchmarks, but can also be used to create arbitrarily complex workloads that do not involve a database server.
sysbench 支持如下的基准测试:
oltp_*.lua
: a collection of OLTP-like database benchmarks (OLTP数据库 如MySQL、Oracle、PostgreSQL)fileio
: a filesystem-level benchmark (文件I/O性能)cpu
: a simple CPU benchmark (CPU性能测试)memory
: a memory access benchmark (内存访问)threads
: a thread-based scheduler benchmark (基于线程的调度性能)mutex
: a POSIX mutex benchmark
2. 特点
- extensive statistics about rate(速率) and latency(延迟) is available, including latency percentiles(统计) and histograms(直方图);
- low overhead even with thousands of concurrent threads. sysbench is capable of generating and tracking hundreds of millions of events per second;
- new benchmarks can be easily created by implementing pre-defined hooks in user-provided Lua scripts;
3. 安装
3.1 二进制安装
Debian/Ubuntu
12curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bashsudo apt -y install sysbenchRHEL/CentOS:
12curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bashsudo yum -y install sysbenchFedora:
12curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bashsudo dnf -y install sysbenchmacOS:
12# Add --with-postgresql if you need PostgreSQL supportbrew install sysbench
3.2 源码构建
推荐使用二进制安装
3.2.1 Build Requirements
Debian/Ubuntu
|
|
RHEL/CentOS
|
|
Fedora
|
|
macOS
**Assuming you have Xcode (or Xcode Command Line Tools) and Homebrew installed:
|
|
3.2.2 Build and Install
|
|
The above will build sysbench with MySQL support by default. If you have MySQL headers and libraries in non-standard locations (and no mysql_config
can be found in the PATH
), you can specify them explicitly with --with-mysql-includes
and --with-mysql-libs
options to ./configure
.
To compile sysbench without MySQL support, use --without-mysql
. If no database drivers are available database-related scripts will not work, but other benchmarks will be functional.
See README-Oracle.md for instructions on building with Oracle client libraries.
4. 语法说明
4.1 sysbench –help
|
|
4.2 命令说明
通用语法
|
|
4.2.1 testname
testname is an optional name of a built-in test (e.g.
fileio
,memory
,cpu
, etc.), or a name of one of the bundled Lua scripts (e.g.oltp_read_only
), or a path to a custom Lua script. If no test name is specified on the command line (and thus, there is no command too, as in that case it would be parsed as a testname), or the test name is a dash (“-
“), then sysbench expects a Lua script to execute on its standard input.
- testname 可以是一个内置的测试 ( 当前支持5种
fileio
,memory
,cpu
,threads
,mutex
.), - 也可以是一个内置的lua脚本名 (e.g.
oltp_read_only
), - a path to a custom Lua script.
- 不指定的情况, then sysbench expects a Lua script to execute on its standard input.
4.2.2 command
command is an optional argument that will be passed by sysbench to the built-in test or script specified with testname. command defines the action that must be performed by the test. The list of available commands depends on a particular test. Some tests also implement their own custom commands.
Below is a description of typical test commands and their purpose:
prepare
: performs preparative actions for those tests which need them, e.g. creating the necessary files on disk for thefileio
test, or filling the test database for database benchmarks.run
: runs the actual test specified with the testname argument. This command is provided by all tests.cleanup
: removes temporary data after the test run in those tests which create one.help
: displays usage information for the test specified with the testname argument. This includes the full list of commands provided by the test, so it should be used to get the available commands.
4.2.3 options
options 包括通用的选项,另外不同的testname也包含特定的option,如mysql测试包含的数据库连接信息。特定测试的option可以通过sysbench testname help
查看。sysbench --help
可以查看通用的option
通用命令行选项
The table below lists the supported common options, their descriptions and default values:
Option | Description | Default value | ||
---|---|---|---|---|
--threads |
The total number of worker threads to create | 创建测试线程的数目。默认为1. | 1 | |
--events |
Limit for total number of requests. 0 (the default) means no limit | 请求的最大数目。0代表不限制 | 0 | |
--time |
Limit for total execution time in seconds. 0 means no limit | 最大执行时间,单位是s。 | 10 | |
–forced-shutdown=STRING | number of seconds to wait after the –time limit before forcing shutdown, or ‘off’ to disable [off] | 超过–time强制中断。默认是off | off | |
--thread-stack-size |
Size of stack for each thread | 每个线程的堆栈大小。 | 64K | |
--rate |
Average transactions rate. The number specifies how many events (transactions) per seconds should be executed by all threads on average. 0 (default) means unlimited rate, i.e. events are executed as fast as possible | 0 | ||
--report-interval |
periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] | 执行过程中,显示执行结果的时间间隔 | 0 | |
--debug |
Print more debug info | 是否显示debug信息 | off | |
--validate |
Perform validation of test results where possible | 在可能情况下执行验证检查。 | off | |
--help |
Print help on general syntax or on a specified test, and exit | 查看帮助 | off | |
--verbosity |
verbosity level {5 - debug, 0 - only critical messages} [3] | 日志详细级别 | 3 | |
--percentile |
percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95] | 表示设定采样比例,默认是 95%,即丢弃5%的长请求,在剩余的99%里取最大值 | 95 | |
–histogram[=on\ | off] | print latency histogram in report [off] | report延迟直方图 | off |
--luajit-cmd |
perform a LuaJIT control command. This option is equivalent to luajit -j . See LuaJIT documentation for more information |
特定测试相关的选项
可以通过sysbench testname help
查看
sysbench fileio help
|
|
sysbench cpu help
|
|
sysbench memory help
|
|
sysbench threads help
|
|
sysbench mutex help
|
|
|
|